include("ersmodule.lua")

local AUTO = {}

function AUTO.ban(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	elseif #args == 2 then
		return {cmd .. strargs .. "<time>"}
	elseif #args == 3 then
		return {cmd .. strargs .. "<reason>"}
	end
end

function AUTO.kick(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	elseif #args == 2 then
		return {cmd .. strargs .. "<reason>"}
	end
end

function AUTO.gag(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	end
end

function AUTO.goto(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	end
end

function AUTO.bring(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	end
end

function AUTO.noclip(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	end
end

function AUTO.spec(cmd, args, strargs)
	if #args == 1 then
		return ers.ConcatOntoTableValues(cmd .. " ", ers.MatchString(args[1], ers.GetPlayerList()))
	elseif #args == 2 then
		return ers.ConcatOntoTableValues(cmd .. strargs,{"1stperson", "3rdperson", "freeroam"})
	end
end

//what a joke.
//totally immune to exploits. (not)
local function RunRealServerCommand(admin, cmd, args)
	LocalPlayer():ConCommand(string.format("_%s %s", string.sub(cmd, 2), table.concat(args, " ")))
end

local function AutoHandler(cmd, strargs)
	local args = string.Explode(" ", strargs)
	table.remove(args, 1)

	/*
	PrintTable(args)
	print("[" .. strargs .. "]")
	print("\n")
	*/
	
	//args that have been completed
	local validargs = string.sub(strargs, 1, -(string.len(args[#args]) + 1))
	
	return AUTO[string.sub(cmd, 2)](cmd, args, validargs)
end

for cmd, func in pairs(AUTO) do
	concommand.Add("." .. cmd, RunRealServerCommand, AutoHandler)
end